package io.renren.utils;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.renren.entity.DataEmpPerformanceEntity;
import io.renren.service.DataEmpPerformanceService;
import io.renren.service.DictDepartmentService;
import io.renren.service.impl.DataEmpPerformanceServiceImpl;
import io.renren.service.impl.DictDepartmentServiceImpl;

public class AssignUtils {
	DictDepartmentService dds = new DictDepartmentServiceImpl();
	
	private static Object object;

	public static List<Map<String,Object>> assignToEmp(List<List<Object>> list){
		List<Map<String,Object>> emps = new ArrayList<Map<String,Object>>();
		Map<String, Object> emp = null;
		for (List<Object> list2 : list) {
			emp = new HashMap<String,Object>();
			emp.put("name",list2.get(0));
			emp.put("birthday",list2.get(1));
			emp.put("gender",0);
			if("男".equals(list2.get(2))){emp.put("gender",1);}else{emp.put("gender",0);}
			emp.put("cardno",list2.get(3));
			emp.put("workno",list2.get(4));
			emp.put("jobno",list2.get(5));
			emp.put("deptno",list2.get(6));
			emp.put("userid",list2.get(7));
			emp.put("inorgtime",list2.get(8));
			emp.put("zztime",list2.get(9));
			emp.put("outorgtime",list2.get(10));
			emp.put("hasorgmobile",list2.get(11));
			if("是".equals(list2.get(11))){emp.put("hasorgmobile",1);}else{emp.put("hasorgmobile",0);}
			emp.put("mobileno",list2.get(12));
			if("是".equals(list2.get(13))){emp.put("hasports",1);}else{emp.put("hasports",0);}
			emp.put("recommender", list2.get(14));
			emp.put("bredManNo",list2.get(15));
			emp.put("createtime", new Date());
			emp.put("createby", ShiroUtils.getUserId());
			emps.add(emp);
		}
		return emps;
	}

	/**
	 * 
	 * @author Murphy Wu导入人力细节
	 * 创建时间：2018年6月7日 下午4:10:03 
	 * 说明 :
	 */
	public static List<Map<String,Object>> assignToEmpNewUuid(List<List<Object>> list,DataEmpPerformanceService dep){
		//绩效排名和绩效奖金在重新导入时就要更新了，把之前的删除
		dep.deleteAll();
		List<Map<String,Object>> emps = new ArrayList<Map<String,Object>>();
		Map<String, Object> emp = null;
		int i=0;
		for (List<Object> list2 : list) {
			String iddata=Common.getUUID().split(",")[1];
			emp = new HashMap<String,Object>();
			emp.put("id",iddata);
			emp.put("name",list2.get(0));
			emp.put("birthday",list2.get(1));
			emp.put("gender",0);
			if("男".equals(list2.get(2))){emp.put("gender",1);}else{emp.put("gender",0);}
			emp.put("cardno",list2.get(3));
			emp.put("workno",list2.get(4));
			emp.put("jobno",list2.get(5));
			emp.put("deptno",list2.get(6));
			emp.put("userid",list2.get(7));
			emp.put("inorgtime",chuLiStringByNull(list2.get(8)));
			emp.put("zztime",chuLiStringByNull(list2.get(9)));
			emp.put("outorgtime",chuLiStringByNull(list2.get(10)));
			/*emp.put("hasorgmobile",list2.get(11));*/
			if("是".equals(list2.get(11))){emp.put("hasorgmobile",1);}else{emp.put("hasorgmobile",0);}
			emp.put("mobileno",list2.get(12));
			if("否".equals(list2.get(13))){emp.put("hasfirstport",0);}else{emp.put("hasfirstport",1);}
			if("是".equals(list2.get(14))){emp.put("hasports",1);}else{emp.put("hasports",0);}
			emp.put("recommender", list2.get(15));
			emp.put("directorbredno",list2.get(16));
			emp.put("branchbredno",list2.get(17));
			emp.put("areabredno",list2.get(18));
			emp.put("bigareabredno",list2.get(19));
			emp.put("daysOfAttendance",list2.get(20));
			//这个是社保状态
			/*emp.put("hassocial",list2.get(21));*/
			if("否".equals(list2.get(21))){emp.put("hassocial",0);}else{emp.put("hassocial",1);}
			if("是".equals(list2.get(22))){emp.put("hashousing",1);}else{emp.put("hashousing",0);}
			String workno = (String)list2.get(4);
			double order = (double)list2.get(23);
			double money = (double)list2.get(24);
			DataEmpPerformanceEntity depe=new DataEmpPerformanceEntity();
			depe.setMoney(new BigDecimal(money));
			depe.setOrder(String.valueOf(order));
			depe.setWorkno(workno);
			dep.save(depe);
			emp.put("createtime", new Date());
			emp.put("createby", ShiroUtils.getUserEntity().getUsername());
			emp.put("orderno",i);
			emp.put("state",1);
			i=i+1;
			emps.add(emp);
		}
		return emps;
	}

	public static List<Map<String,Object>> assignToDept(List<List<Object>> list){
		List<Map<String,Object>> categorys = new ArrayList<Map<String,Object>>();
		Map<String, Object> category = null;
		for (List<Object> list2 : list) {
			category = new HashMap<String,Object>();
			category.put("name",list2.get(0));
			category.put("deptno",list2.get(1));
			String level = parseString(list2.get(2));
			if("0".equals(level)){category.put("level",null);}else{category.put("level",level);}
			category.put("parentid",list2.get(3));
			category.put("employeeid",list2.get(4));
			categorys.add(category);
		}

		return categorys;
	}

	/**
	 * 
	 * @author Murphy Wu
	 * 创建时间：2018年6月7日 上午10:19:09 
	 * 说明 :新UUID生成发，生成转换部门保存数据
	 */
	public static List<Map<String,Object>> assignToDeptNewUuid(List<List<Object>> list){
		List<Map<String,Object>> categorys = new ArrayList<Map<String,Object>>();
		Map<String, Object> category = null;
		int i=0;
		for (List<Object> list2 : list) {
			String iddata=Common.getUUID().split(",")[1];
			category = new HashMap<String,Object>();
			category.put("id",iddata);
			category.put("name",list2.get(0));
			category.put("deptno",list2.get(1));
			String level = parseString(list2.get(2));
			if("0".equals(level)){category.put("level",null);}else{category.put("level",level);}
			category.put("parentid",list2.get(3).toString().equals("#")?"":list2.get(3));
			category.put("employeeid",list2.get(4));
			category.put("orderno",i);
			i=i+1;
			categorys.add(category);
		}

		return categorys;
	}

	public static List<Map<String,String>> assignToDeptEmp(List<List<Object>> list){
		List<Map<String,String>> deptEmps = new ArrayList<Map<String,String>>();
		Map<String,String> deptEmp = null; 
		for (List<Object> list2 : list) {
			deptEmp = new HashMap<String, String>();
			deptEmp.put("deptName", list2.get(0).toString());
			deptEmp.put("empNo", parseString(list2.get(1)));
			deptEmps.add(deptEmp);
		}

		return deptEmps;
	}

	public static String parseString(Object obj){
		Integer str = (int)Double.parseDouble(obj.toString());
		return str.toString();
	}

	public static List<Map<String,Object>> assignToContract(List<List<Object>> list){
		List<Map<String,Object>> contracts = new ArrayList<Map<String,Object>>();
		Map<String, Object> contract = null;
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMM");
		for (List<Object> list2 : list) {
			contract = new HashMap<String,Object>();
			contract.put("contractNo", list2.get(0));
			contract.put("contractName", list2.get(1));
			contract.put("contractDate", list2.get(2));
			contract.put("contractMonth", formatter.format(list2.get(2)));
			contract.put("contractTypeId", parseString(list2.get(3)));
			contract.put("address", list2.get(4));
			contract.put("contractMoney", list2.get(5));
			contract.put("hasPaidMoney", list2.get(6));
			contract.put("thisMonthPaidMoney", list2.get(7));
			contract.put("payDate", list2.get(8));
			contract.put("noPaidMoney", list2.get(9));
			contract.put("employeeID", list2.get(10));
			contract.put("splitEmployeeIDList", list2.get(11));
			contract.put("splitPercent", list2.get(12));
			contracts.add(contract);
		}
		return contracts;
	}

	/**
	 * 
	 * @author Murphy Wu
	 * 创建时间：2018年6月8日 上午8:53:35 
	 * 说明 :
	 */
	public static List<Map<String,Object>> assignToContractNewUuid(List<List<Object>> list){
		List<Map<String,Object>> contracts = new ArrayList<Map<String,Object>>();
		Map<String, Object> contract = null;
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMM");
		for (List<Object> list2 : list) {
			String zhuNo="";
			String zhuName="";
			String zhuFen="";
			String zhuGe="";
			if (list2.get(11)!=null && list2.get(11).toString().length()!=0) {
				zhuNo=list2.get(11).toString();
				zhuName=list2.get(12).toString();
				zhuFen=list2.get(13).toString();
				zhuGe=list2.get(14).toString();
				if (list2.get(15)!=null && list2.get(15).toString().length()!=0) {
					zhuNo=zhuNo+","+list2.get(15).toString();
					zhuName=zhuName+","+list2.get(16).toString();
					zhuFen=zhuFen+","+list2.get(17).toString();
					zhuGe=zhuGe+","+list2.get(18).toString();
				}
				if (list2.get(19)!=null && list2.get(19).toString().length()!=0) {
					zhuNo=zhuNo+","+list2.get(19).toString();
					zhuName=zhuName+","+list2.get(20).toString();
					zhuFen=zhuFen+","+list2.get(21).toString();
					zhuGe=zhuGe+","+list2.get(22).toString();
				}
				if (list2.get(23)!=null && list2.get(23).toString().length()!=0) {
					zhuNo=zhuNo+","+list2.get(23).toString();
					zhuName=zhuName+","+list2.get(24).toString();
					zhuFen=zhuFen+","+list2.get(25).toString();
					zhuGe=zhuGe+","+list2.get(26).toString();
				}
				if (list2.get(27)!=null && list2.get(27).toString().length()!=0) {
					zhuNo=zhuNo+","+list2.get(27).toString();
					zhuName=zhuName+","+list2.get(28).toString();
					zhuFen=zhuFen+","+list2.get(29).toString();
					zhuGe=zhuGe+","+list2.get(30).toString();
				}
				if (list2.get(31)!=null && list2.get(31).toString().length()!=0) {
					zhuNo=zhuNo+","+list2.get(31).toString();
					zhuName=zhuName+","+list2.get(32).toString();
					zhuFen=zhuFen+","+list2.get(33).toString();
					zhuGe=zhuGe+","+list2.get(34).toString();
				}
			}else{

			}

			String iddata=Common.getUUID().split(",")[1];
			contract = new HashMap<String,Object>();
			contract.put("id",iddata);
			contract.put("contractno", list2.get(0));
			contract.put("contractname", list2.get(1));
			contract.put("contractdate", list2.get(2));
			contract.put("contractmonth", formatter.format(list2.get(2)));
			contract.put("contracttypeid", list2.get(0).toString().substring(0,2));
			contract.put("address", list2.get(3));
			contract.put("contractmoney", list2.get(4));
			contract.put("haspaidmoney", list2.get(5));
			contract.put("thismonthpaidmoney", list2.get(6));
			contract.put("paydate", list2.get(7));
			contract.put("nopaidmoney", list2.get(8));
			contract.put("employeeid", list2.get(9));
			contract.put("employeename", list2.get(10));
			contract.put("splitemployeeidlist", zhuNo);
			contract.put("splitemployeeworknolist", zhuNo);
			contract.put("splitemployeenamelist", zhuName);
			contract.put("splitpercent", zhuFen);
			contract.put("everyoneNo", zhuGe);
			contract.put("everyoneno", zhuGe);
			contract.put("memo", list2.get(35));
			contracts.add(contract);
		}
		return contracts;
	}

	/**
	 * 
	 * @author Murphy Wu
	 * 创建时间：2018年6月7日 上午10:19:09 
	 * 说明 :新UUID生成发，生成转换部门保存数据
	 */
	public static List<Map<String,Object>> assignToAddMoneyNewUuid(List<List<Object>> list,String year,String month){
		List<Map<String,Object>> categorys = new ArrayList<Map<String,Object>>();
		Map<String, Object> category = null;
		int i=0;
		for (List<Object> list2 : list) {
			String iddata=Common.getUUID().split(",")[1];
			category = new HashMap<String,Object>();
			category.put("id",iddata);
			category.put("workno",list2.get(0));
			category.put("workname",list2.get(1));
			/*category.put("cardno",list2.get(2));*/
			category.put("money",list2.get(2));
			category.put("orderno",i);
			category.put("memo",list2.get(3));
			category.put("year",year);
			category.put("month",month);
			category.put("createtime",new Date());
			category.put("createby",ShiroUtils.getUserEntity().getUsername());
			i=i+1;
			categorys.add(category);
		}

		return categorys;
	}



	/**
	 * 
	 * @author Murphy Wu
	 * 创建时间：2018年6月7日 上午10:19:09 
	 * 说明 :新UUID生成发，生成转换部门保存数据
	 */
	public static List<Map<String,Object>> assignToLostMoneyNewUuid(List<List<Object>> list,String year,String month){
		List<Map<String,Object>> categorys = new ArrayList<Map<String,Object>>();
		Map<String, Object> category = null;
		int i=0;
		for (List<Object> list2 : list) {
			String iddata=Common.getUUID().split(",")[1];
			category = new HashMap<String,Object>();
			category.put("id",iddata);
			category.put("workno",list2.get(0));
			category.put("workname",list2.get(1));
			/*category.put("cardno",list2.get(2));*/
			category.put("money",list2.get(2));
			category.put("orderno",i);
			category.put("memo",list2.get(3));
			category.put("year",year);
			category.put("month",month);
			category.put("createtime",new Date());
			category.put("createby",ShiroUtils.getUserEntity().getUsername());
			i=i+1;
			categorys.add(category);
		}

		return categorys;
	}

	public static Object chuLiStringByNull(Object datastring){
		if (datastring==null) {
			return null;
		} else {
			if (datastring.toString().length()==0) {
				return null;
			} else {
				return datastring;
			}
		}

	}


}
